home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / progwin.zip / RESOURC2.ZIP / RESOURC2.C < prev    next >
C/C++ Source or Header  |  1991-10-11  |  3KB  |  104 lines

  1. /*----------------------------------------------------------
  2.  RESOURCE2.C -- Icon and Cursor Demonstration Program No. 2
  3.         (c) Charles Petzold, 1990
  4. ------------------------------------------------------------*/
  5.  
  6. #include <windows.h>
  7.  
  8. long FAR PASCAL WndProc  (HWND, WORD, WORD, LONG) ;
  9.  
  10. char   szAppName [] = "Resourc2" ;
  11. HANDLE hInst ;
  12.  
  13. int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance,
  14.             LPSTR lpszCmdLine, int nCmdShow)
  15.      {
  16.       HBITMAP  hBitmap ;
  17.       HBRUSH   hBrush ;
  18.       HWND     hwnd ;
  19.       MSG      msg ;
  20.       WNDCLASS wndclass ;
  21.  
  22.       hBitmap = LoadBitmap (hInstance, szAppName) ;
  23.       hBrush = CreatePatternBrush (hBitmap) ;
  24.  
  25.  
  26. if (!hPrevInstance)
  27.      {
  28.      wndclass.style        = CS_HREDRAW | CS_VREDRAW ;
  29.      wndclass.lpfnWndProc  = WndProc ;
  30.      wndclass.cbClsExtra   = 0 ;
  31.      wndclass.cbWndExtra   = 0 ;
  32.      wndclass.hInstance    = hInstance ;
  33.      wndclass.hIcon        = LoadIcon (hInstance, szAppName) ;
  34.      wndclass.hCursor      = LoadCursor (hInstance, szAppName) ;
  35.      wndclass.hbrBackground= hBrush ;
  36.      wndclass.lpszMenuName = NULL ;
  37.      wndclass.lpszClassName= szAppName ;
  38.      RegisterClass (&wndclass) ;
  39.      }
  40.  
  41. hInst = hInstance ;
  42.  
  43. hwnd = CreateWindow (szAppName, "Icon and Cursor Demo",
  44.              WS_OVERLAPPEDWINDOW,
  45.              CW_USEDEFAULT, CW_USEDEFAULT,
  46.              CW_USEDEFAULT, CW_USEDEFAULT,
  47.              NULL, NULL, hInstance, NULL) ;
  48.  
  49. ShowWindow (hwnd, nCmdShow) ;
  50. UpdateWindow (hwnd) ;
  51.  
  52. while (GetMessage (&msg, NULL, 0, 0))
  53.      {
  54.      TranslateMessage (&msg) ;
  55.      DispatchMessage (&msg) ;
  56.      }
  57.  
  58.      DeleteObject (hBrush) ;     // clean up
  59.      DeleteObject (hBitmap) ;
  60.  
  61. return msg.wParam ;
  62. }
  63.  
  64. long FAR PASCAL WndProc (HWND hwnd, WORD message, WORD wParam, LONG lParam)
  65.      {
  66.      static HICON hIcon ;
  67.      static short cxIcon, cyIcon, cxClient, cyClient ;
  68.      HDC          hdc ;
  69.      RECT         rect ;
  70.      PAINTSTRUCT  ps ;
  71.      short        x, y ;
  72.  
  73. switch (message)
  74.      {
  75.      case WM_CREATE :
  76.       hIcon = LoadIcon (hInst, szAppName) ;
  77.       cxIcon = GetSystemMetrics (SM_CXICON) ;
  78.       cyIcon = GetSystemMetrics (SM_CYICON) ;
  79.       return 0 ;
  80.  
  81.      case WM_SIZE :
  82.       cxClient = LOWORD (lParam) ;
  83.       cyClient = HIWORD (lParam) ;
  84.       return 0 ;
  85.  
  86.      case WM_PAINT :
  87.  
  88.        hdc = BeginPaint (hwnd, &ps) ;
  89.     
  90.        for (y = cyIcon ; y < cyClient ; y+= 2 * cyIcon)
  91.         for (x = cxIcon ; x < cxClient ; x += 2 * cxIcon)
  92.              DrawIcon (hdc, x, y, hIcon) ;
  93.  
  94.        EndPaint (hwnd, &ps) ;
  95.      return 0 ;
  96.  
  97.      case WM_DESTROY :
  98.       PostQuitMessage (0) ;
  99.       return 0 ;
  100. }
  101. return DefWindowProc (hwnd, message, wParam, lParam) ;
  102. }
  103.  
  104.